import BasePanel from "./BasePanel";
import EnumData from "../../Enum/EnumData";
import CommonConstant from "../../constant/CommonConstant";
import Sound from "../../constant/SoundNameConstant";
import SelectLevelPanel from "./SelectLevelPanel";

//给图片设置sprite
//var fishIcon: GImage = fishIconCom.getChild("fishIcon").asImage;
//fishIcon.icon = "ui://CommonUI/" + (num)";   路径未已加载的图片的包名+文件名


//设置组件或者图片的大小
//   mainCom = fairygui.UIPackage.createObject(packName, panel).asCom;
//mainCom.setSize(fairygui.GRoot.inst.width, fairygui.GRoot.inst.height);


//给fui添加组件
//        let jp: fairygui.GComponent = this.m_fui.getChild("jp").asCom;
//let jpb: jpBeat = jp.displayObject.addComponent(jpBeat);

//fui list 添加item
// this.infoList = this.m_fui.getChild("infoList").asList;
//this.infoList.removeChildrenToPool();
//for (var i: number = 0; i < info.length; i++) {
//var infoCom: GComponent = this.infoList.addItemFromPool().asCom;
//infoCom.getChild("bgLoader").asLoader;


//按钮绑点击事件
//byBtn.onClick(this, () => { this.onBuyClick(1, p) });

export default class MainUIPanel extends BasePanel {

    private startGameBtn:fairygui.GButton;

    private inputLevel:fairygui.GTextInput;

    constructor(id) {
        super();
        this.m_nameID = id;
    }

    public EnterMainScene(){
        this.InitFui();
    }

    private InitFui(): void {
        fairygui.UIPackage.addPackage(CommonConstant._fuiMainUIPanelPath.Package);
        this.m_fui = fairygui.UIPackage.createObject("MainUIPanel", "MainUIPanel").asCom;
        window.gameFacade.SceneMng.AddFUI(this.m_fui);
        this.startGameBtn = this.m_fui.getChild("startBtn").asButton;
        this.inputLevel = this.m_fui.getChild("input").asTextInput;
        // window.gameFacade.SceneMng.Create(EnumData.EnumPanelType.MarqueePanel, false);

        this.startGameBtn.onClick(this, this.OnStartGameBtnClick);
        this.sound();
        super.Show();
    }

    private OnStartGameBtnClick() {
       
        window.gameFacade.SceneMng.Create(EnumData.EnumPanelType.SelectLevelPanel) as SelectLevelPanel;
    }

    public ExitMainScene() {
        //卸载3d资源缓存
        window.gameFacade.SoundMng.stopAll();
        window.gameFacade.ResourceMng.ReleaseFuiResByGroupName(CommonConstant._groupName_fuiRes);
    }

    private sound(): void {
        // this.settingBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.reportBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.rebateActBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.helpBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.rankingBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.jpBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.walletBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.preBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.rateSelect) });
        // this.nextBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.rateSelect) });
        // this.fastBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onClick) });
        // this.backMainPageBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onClick) });
        // this.personnalInfoBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.lvBonusBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.growthFundBtn.onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onOpen) });
        // this.m_fui.getChild("bgBtn").onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onClick) });
        // this.m_islandInfoPanel.getChild("RateBtn").onClick(this, () => { this.onPlaySound(Sound.soundKeyArr.onClick) });
        window.gameFacade.SoundMng.playMusic(Sound.soundBgArr.BGM);
    }
}